package lib.gt.map;

import android.graphics.drawable.Drawable;

import com.google.android.maps.OverlayItem;

public class MyLocationOverlay extends AbsItemizedOverlay {
	
	private OverlayItem mLocaitonOverlayItem;
	
	public MyLocationOverlay(Drawable d) {
		super(boundCenter(d));
	}

	@Override
	protected OverlayItem createItem(int index) {
		return mLocaitonOverlayItem;
	}

	@Override
	public int size() {
		return mLocaitonOverlayItem == null ? 0 : 1;
	}
	
	@Override
	protected boolean onTap(int index) {
		boolean interrupt = super.onTap(index);
		if(!interrupt && OverlayManager.hasInit()) {
			OverlayManager.getInstance().getMapView().getController().animateTo(getCenter());
			OverlayManager.getInstance().showPopupView(index);
		}
		return interrupt;
	}
	
	public void updateMyLocationOverlayItem(OverlayItem item) {
		mLocaitonOverlayItem = null;
		mLocaitonOverlayItem = item;
		populate();
	}

	@Override
	public void release() {
		super.release();
		mLocaitonOverlayItem = null;
	}
}
